import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import { VitePWA } from "vite-plugin-pwa"
import VitePluginMd from "./plugin/vite-plugin-md"
import VitePluginJson from "./plugin/vite-plugin.json"
import { resolve } from "path"

export default defineConfig({
  server: {
    port: 3000,
    host: "0.0.0.0",
  },
  define: {
    _VUE_OPTIONS_API_: JSON.stringify(false),
  },
  assetsInclude: ["icon.png", "articles/*.md"],
  build: {
    cssCodeSplit: false,
    chunkSizeWarningLimit: 1024,

    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes("node_modules")) {
            return id.toString().split("node_modules/")[1].split("/")[0].toString()
          }
        },
      },
    },
  },
  // server: {
  //   port: 3333,
  //   proxy: {
  //     "/Api/": "https://fuyouplus.cn",
  //   },
  // },
  plugins: [
    vue({
      template: {
        compilerOptions: {
          // 将所有包含短横线的标签作为自定义元素处理
          // isCustomElement: tag => tag.includes("my-"),
        },
      },
    }),
    VitePluginMd(),
    VitePluginJson(),
    VitePWA({
      registerType: "autoUpdate",
      devOptions: {
        enabled: true,
      },
      manifest: {
        icons: [
          {
            src: "/assets/icon-f111d216.png",
            sizes: "200x200",
            type: "image/png",
          },
        ],
      },
    }),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/styles/index.module.scss";`, //全局混入scss
      },
    },
  },
  resolve: {
    extensions: [".js", ".ts", ".tsx", ".jsx"],
    alias: [
      //配置路径别名
      { find: "@", replacement: resolve(__dirname, "src") },
      { find: "@cop", replacement: resolve(__dirname, "src/components") },
      { find: "@api", replacement: resolve(__dirname, "src/api") },
    ],
  },
})
